package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.admin.util.UserContext;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/travel")
public class TravelController {
    @Autowired
    private ITravelService travelService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") TravelQueryObject qo) {
        qo.setState(Travel.STATE_REVIEW);
        PageInfo pageInfo = travelService.getList(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "travel/list";
    }
    @RequestMapping("/passList")
    public String passList(Model model, @ModelAttribute("qo") TravelQueryObject qo) {
        qo.setState(Travel.STATE_PASS);
        System.out.println(qo);
        PageInfo pageInfo = travelService.getList(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "passTravel/list";
    }
    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(Travel travel) {
        JSONResult json = new JSONResult();
        try{
        travelService.changeState(travel);

        }catch (Exception e){
            e.printStackTrace();
            json.mark(e.getMessage());
        }
        return json;
    }
    @RequestMapping("/getContent")
    @ResponseBody
    public Object getContent(Long id) {
        JSONResult json = new JSONResult();
        Travel travel=travelService.getContent(id);
        return travel;
    }



    @RequestMapping("/save")
    @ResponseBody
    public Object saveOrUpdate(Travel travel) {
        JSONResult json = new JSONResult();
        travelService.saveOrUpdate(travel);
        return json;
    }


}
